package com.white.movies.Utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.white.movies.R;

public class Tools {
    static public void setImage(String img, ImageView imgView, Context context) {
        if (img.contains(".")) {
            img = img.substring(0, img.lastIndexOf("."));
        }
        int imageResId = context.getResources().getIdentifier(img, "mipmap", context.getPackageName());
        if (imageResId != 0) {
            RequestOptions requestOptions = new RequestOptions().transform(new CenterCrop(), new RoundedCorners(60));
            Glide.with(context).load(imageResId).apply(requestOptions).into(imgView);
        } else {
            imgView.setImageResource(R.mipmap.no_exsits);
        }
    }
}
